﻿




using System.Web.Mvc;
using Hotpot.Modules.Conferences.Models;

namespace Hotpot.Modules.Conferences.ModelBinders
{
    public class SpeakerFilterCriteriaModelBinder : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            SpeakerFilterCriteria speakerFilterCriteria = 
                new SpeakerFilterCriteria(controllerContext.RouteData.Values["speakerFilterCriteria"] as string);

            if (string.IsNullOrEmpty(speakerFilterCriteria.Term) &&
                !string.IsNullOrEmpty(controllerContext.HttpContext.Request.QueryString["term"]))
                speakerFilterCriteria.Term =
                    controllerContext.HttpContext.Request.QueryString["term"];

            return speakerFilterCriteria;
        }
    }
}